package com.team.olympic.controller;

import java.sql.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import com.team.olympic.service.MatchService;
import com.team.olympic.pojo.Response;

@CrossOrigin
@RestController
public class MatchController {
    @Autowired
    private MatchService matchService;

    @GetMapping("/matches")
    public Response<?> findAllMatches() {
        return Response.success(matchService.findAllMatches());
    }

    /**
     * 根据日期查询比赛
     * @param startDate 比赛开始时间
     * 写法如下
     * http://localhost:8080/matchByStartDate?startDate=2024-08-01 <strong>注意替换ip和端口号以及日期</strong>
     * @return Response(包含比赛信息) {@link com.team.olympic.pojo.Response}
     */
    @GetMapping("/matchByStartDate")
    public Response<?> findMatchByDate(@RequestParam Date startDate) {
        return Response.success(matchService.findMatchByDate(startDate));
    }

    /**
     * 根据比赛ID查询对应比赛获胜的用户
     * @param matchId 比赛ID
     * @return Response(包含比赛信息) {@link com.team.olympic.pojo.Response} 包含{@link com.team.olympic.vo.WinMatchVo}
     */
    @GetMapping("/matchVosByMatchId")
    public Response<?> findMatchVosByMatchId(@RequestParam Long matchId) {
        return Response.success(matchService.findMatchVosByMatchId(matchId));
    }

    @GetMapping("/matchVosByUserId")
    public Response<?> fWinMatchVosByUserId(@RequestParam Long userId) {
        return Response.success(matchService.fWinMatchVosByUserId(userId));
    }

    @GetMapping("/matchVos")
    public Response<?> findAllMatchVos() {
        return Response.success(matchService.findAllMatchVos());
    }
}
